class Solution:
    def myPow(self, x: float, n: int) -> float:
        r = 1.0
        if n == 0:
            return 1
        neg = False
        if n<0:
            neg = True
        n = abs(n)
        while n>0:
            if n&1!=0:
                r = x * r
            n = n>>1
            if n!=0:
                x = x*x
        return r if not neg else 1/r

if __name__ == '__main__':
    s = Solution()
    x = 2.0
    n = -2
    r = s.myPow(x, n)
    # r = s.findMedianSortedArraysByOne(nums1)
    print(r)
    # print(nums1[:-1])
